<?php
require("includes/basic.php");
$project=$_POST['project'];
$task=$_POST['title'];
$taskdesc=addslashes($_POST['task-desc']);
$creator=$userId;
$taskpriority=$_POST['priority'];
$etime=$_POST['etime'];
$phase=$_POST['phase'];
$module=$_POST['module'];
$sql=mysql_query("insert into task_master (`project_id`,`task_title`,`task_description`,`task_priority`,`task_created_on`,`task_created_by`,`estimated_time`,`phase_id`,`module_id`) values ('$project','$task','$taskdesc','$taskpriority',sysdate(),'$creator','$etime','$phase','$module')");
if($sql)
{
	$sql1=mysql_query("select * from task_master order by task_id desc limit 1");
	$sql1r=mysql_fetch_array($sql1);
	extract($sql1r);
	$taskid=$sql1r['task_id'];
	if(isset($_POST['submit']) && $_FILES['uploadedfile']['size'] > 0)
	{
		$fileName = $_FILES['uploadedfile']['name'];
		$tmpName = $_FILES['uploadedfile']['tmp_name'];
		$fileSize = $_FILES['uploadedfile']['size'];
		$fileType = $_FILES['uploadedfile']['type'];
		$fp      = fopen($tmpName, 'r');
		$content = fread($fp, filesize($tmpName));
		$content = addslashes($content);
		fclose($fp);
		if(!get_magic_quotes_gpc())
		{
			$fileName = addslashes($fileName);
		}
		$query = "INSERT INTO task_doc (name, size, type, content, task_id, uploaded_on, uploaded_by) VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$taskid', sysdate( ), '$creator')";
		mysql_query($query) or die('Error, query failed'); 
		//$filePath = $target_path . $fileName;
		//$result = move_uploaded_file($tmpName, $filePath);
		//if (!$result) {
		//echo "Error uploading file";
		//exit;
		//}
		//echo "uploaded";
	}
if(isset($_POST['submit']) && $_FILES['file']['size'] > 0)
	{
		$fileName1 = $_FILES['file']['name'];
		$tmpName1 = $_FILES['file']['tmp_name'];
		$fileSize1 = $_FILES['file']['size'];
		$fileType1 = $_FILES['file']['type'];
		$fp1      = fopen($tmpName1, 'r');
		$content1 = fread($fp1, filesize($tmpName1));
		$content1 = addslashes($content1);
		fclose($fp1);
		if(!get_magic_quotes_gpc())
		{
			$fileName1 = addslashes($fileName1);
		}
		$query = "INSERT INTO task_doc (name, size, type, content, task_id, uploaded_on, uploaded_by) VALUES ('$fileName1', '$fileSize1', '$fileType1', '$content1', '$taskid', sysdate(), '$creator')";
		mysql_query($query) or die('Error, query failed'); 
		//$filePath = $target_path . $fileName;

		//$result = move_uploaded_file($tmpName, $filePath);
		//if (!$result) {
		//echo "Error uploading file";
		//exit;
		//}
		//echo "uploaded";
	}
if(isset($_POST['submit']) && $_FILES['file2']['size'] > 0)
	{
		$fileName2 = $_FILES['file2']['name'];
		$tmpName2 = $_FILES['file2']['tmp_name'];
		$fileSize2 = $_FILES['file2']['size'];
		$fileType2 = $_FILES['file2']['type'];
		$fp2      = fopen($tmpName2, 'r');
		$content2 = fread($fp2, filesize($tmpName2));
		$content2 = addslashes($content2);
		fclose($fp2);
		if(!get_magic_quotes_gpc())
		{
			$fileName2 = addslashes($fileName2);
		}
		$query = "INSERT INTO task_doc (name, size, type, content, task_id, uploaded_on, uploaded_by) VALUES ('$fileName2', '$fileSize2', '$fileType2', '$content2', '$taskid', sysdate(), '$creator')";
		mysql_query($query) or die('Error, query failed'); 
		//$filePath = $target_path . $fileName;
		//$result = move_uploaded_file($tmpName, $filePath);
		//if (!$result) {
		//echo "Error uploading file";
		//exit;
		//}
		//echo "uploaded";
	}
	if(isset($_POST['submit']) && $_FILES['file3']['size'] > 0)
	{
		$fileName3 = $_FILES['file3']['name'];
		$tmpName3 = $_FILES['file3']['tmp_name'];
		$fileSize3 = $_FILES['file3']['size'];
		$fileType3 = $_FILES['file3']['type'];
		$fp3      = fopen($tmpName3, 'r');
		$content3 = fread($fp3, filesize($tmpName3));
		$content3 = addslashes($content3);
		fclose($fp3);
		if(!get_magic_quotes_gpc())
		{
			$fileName3 = addslashes($fileName3);
		}
		$query = "INSERT INTO task_doc (name, size, type, content, task_id, uploaded_on, uploaded_by) VALUES ('$fileName3', '$fileSize3', '$fileType3', '$content3', '$taskid', sysdate(), '$creator')";
		mysql_query($query) or die('Error, query failed'); 
		//$filePath = $target_path . $fileName;
		//$result = move_uploaded_file($tmpName, $filePath);
		//if (!$result) {
		//echo "Error uploading file";
		//exit;
		//}
		//echo "uploaded";
	}
if(isset($_POST['submit']) && $_FILES['file4']['size'] > 0)
	{
		$fileName4 = $_FILES['file4']['name'];
		$tmpName4 = $_FILES['file4']['tmp_name'];
		$fileSize4 = $_FILES['file4']['size'];
		$fileType4 = $_FILES['file4']['type'];
		$fp4      = fopen($tmpName4, 'r');
		$content4 = fread($fp4, filesize($tmpName4));
		$content4 = addslashes($content4);
		fclose($fp4);
		if(!get_magic_quotes_gpc())
		{
			$fileName4 = addslashes($fileName4);
		}
		$query = "INSERT INTO task_doc (name, size, type, content, task_id, uploaded_on, uploaded_by) VALUES ('$fileName4', '$fileSize4', '$fileType4', '$content4', '$taskid', sysdate(), '$creator')";
		mysql_query($query) or die('Error, query failed'); 
		//$filePath = $target_path . $fileName;
		//$result = move_uploaded_file($tmpName, $filePath);
		//if (!$result) {
		//echo "Error uploading file";
		//exit;
		//}
		//echo "uploaded";
	}
if(isset($_POST['submit']) && $_FILES['file5']['size'] > 0)
	{
		$fileName5 = $_FILES['file5']['name'];
		$tmpName5 = $_FILES['file5']['tmp_name'];
		$fileSize5 = $_FILES['file5']['size'];
		$fileType5 = $_FILES['file5']['type'];
		$fp5      = fopen($tmpName5, 'r');
		$content5 = fread($fp5, filesize($tmpName5));
		$content5 = addslashes($content5);
		fclose($fp5);
		if(!get_magic_quotes_gpc())
		{
			$fileName5 = addslashes($fileName5);
		}
		$query = "INSERT INTO task_doc (name, size, type, content, task_id, uploaded_on, uploaded_by) VALUES ('$fileName5', '$fileSize5', '$fileType5', '$content5', '$taskid', sysdate(), '$creator')";
		mysql_query($query) or die('Error, query failed'); 
		//$filePath = $target_path . $fileName;
		//$result = move_uploaded_file($tmpName, $filePath);
		//if (!$result) {
		//echo "Error uploading file";
		//exit;
		//}
		//echo "uploaded";
	}
	$addstatus=mysql_query("insert into task_status (`task_id`,`task_status`) values ('$taskid','1')");	
}
if($sql && $addstatus)
{
	header("location:view-task.php?pid=$project&sid=$phase&mid=$module");
}

?>